<?php
namespace Admin\Controller;
//use Think\Controller;
use Tools\AdminController;
class CatController extends AdminController {

    //    栏目列表
    public function column(){
        $catModel = new \Model\CatModel;
        $tree = $catModel->getTree();
        $this->assign('tree',$tree);
        $this->display();
   }
//    栏目添加   
    public function columnadd(){
       $catModels = new \Model\CatModel;
       if(!IS_POST){
        $cat = $catModels->field('cat_id,cat_name,parent_id')->select();
        $this->assign('cats',$cat);
                $this->display();
                exit();
        }else{
            if(I('post.pid') ===""){
               $add = ['intro'=>I('post.intro'),'cat_name'=>I('post.cat_name'),'add_time'=>time()];
            }else{
               $add = ['parent_id'=>I('post.pid'),'cat_name'=>I('post.cat_name'),'add_time'=>time(),'intro'=>I('post.intro')];
                }
            $cattype = $catModels->add($add);
           //  $catModels->name = $_POST['name'];
           // dump($catModels->cat_name);
           // exit;
            if($cattype){
                    $this->redirect('column');
                }else{
                    $this->error('添加失败');
            } 
        }           
    }
}

 